const int buttonPin = 5; // Pin where the button is connected int buttonState = 0; // Variable to store the button state void setup() { // Initialize the serial communication Serial.begin(9600); // Set the button pin as input with internal pull-up resistor enabled pinMode(buttonPin, INPUT_PULLUP); } void loop() { // Read the state of the button buttonState = digitalRead(buttonPin); // Check if the button is pressed if (buttonState == LOW) { // If the button is pressed, print a message Serial.println("Button pressed"); } else { // If the button is not pressed, print a different message Serial.println("Button not pressed"); } // Add a small delay to avoid rapid message spamming delay(100); }